package sg.org.scs.splashawards.dao;



import org.hibernate.Query;
import org.hibernate.Session;

import sg.org.scs.splashawards.AbstractDAO.AbstractDAO;
import sg.org.scs.splashawards.dto.Participation;
import sg.org.scs.splashawards.dto.Team;
import sg.org.scs.splashawards.exceptions.DAOException;

public class TeamDAO extends AbstractDAO{

	public void insertTeam(Team team) throws DAOException{
	   super.save(team);
	}
	
	
	public Team getTeam(String teamName) throws DAOException {
		String HQL = "from Team where teamName =:teamName";
		Session session = super.getSession();
		Query q = session.createQuery(HQL);
		q.setParameter("teamName", teamName);
		Team team = (Team)q.uniqueResult();
		session.close();
		return team;
	}
	
	public Team getTeam(int teamId) throws DAOException{
		String HQL = "from Team where teamId =:teamId";
		startOperation();
		Session session = super.getSession();
		Query q = session.createQuery(HQL);
		q.setInteger("teamId", teamId);
		Team team = (Team)q.uniqueResult();
		session.close();
		return team;
	}
	
}
